package com.jbp.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jbp.model.User;
import com.jbp.service.TecentMsgService;
import com.jbp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 同步历史用户信息
 * */
//@Component
//@Configuration
public class TecentMsgInitRunner {

    @Autowired
    private UserService userService;

    @Autowired
    private TecentMsgService tecentMsgService;

    /**
     * 同步历史用户
     */
    @Scheduled(fixedDelay = 10*1000)
    public void quitRoom(){
//        System.out.println("同步历史用户");
        List<User> list = userService.list(new QueryWrapper<User>()
                .orderByDesc("id")
                .last("limit 300")
        );
        list.forEach(user -> {
            boolean result = tecentMsgService.accountImport(user);
            if (!result) {
                tecentMsgService.addUser(user.getId(), false);
            }
        });
//        tecentMsgService.addUser(1000036837);
    }
}
